package com.example.shop.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.shop.domain.Goods;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface GoodsMapper extends BaseMapper<Goods> {
    @Select("SELECT gs.*,us.* FROM t_goods gs,t_user us WHERE gs.user_id = #{userId} AND us.id=#{userId}")
    List<Goods> select(Integer user_id);

    //查找本人的商品
    @Select("SELECT gs.*,us.* FROM t_goods gs,t_user us WHERE gs.user_id = #{userId} AND gs.id= #{id} AND us.id=#{userId}")
    List<Goods> selectListById(Goods goods);

    //查找所有的商品
    @Select("SELECT gs.*,us.* FROM t_goods gs,t_user us WHERE gs.user_id = us.id AND gs.id= #{id}  ")
    List<Goods> selectOneById(Goods goods);

    @Select({
            "<script>",
            "SELECT gs.*, us.* FROM t_goods gs, t_user us",
            "WHERE gs.user_id = us.id",
            "AND gs.status = 0",
            "<if test='name != null'>",
            "AND gs.name LIKE CONCAT('%', #{name}, '%')",
            "</if>",
            "</script>"
    })
    List<Goods> selectByName(String name);

    @Select({
            "<script>",
            "SELECT gs.*, us.* FROM t_goods gs, t_user us",
            "WHERE gs.user_id = us.id",
            "<if test='name != null'>",
            "AND gs.name LIKE CONCAT('%', #{name}, '%')",
            "</if>",
            "</script>"
    })
    List<Goods> selectAllByName(String name);
}
